package uk.co.kevinlockwood.kol.pages;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.List;

public class KoLDroidVersionPage extends KoLPage {
	private static final String BETA_VERSION_URL = "http://kevinlockwood.co.uk/kol/koldroid/latest.php?beta=true&news=true";
	private static final String VERSION_URL = "http://kevinlockwood.co.uk/kol/koldroid/latest.php?news=true";
	private Boolean beta;
	private String version;
	private String news;

	public KoLDroidVersionPage(Boolean beta) {
		this.beta = beta;
		version = null;
		news = "";
	}

	@Override
	public URL fullUrl() throws MalformedURLException {
		URL url = null;
		if (beta) {
			url = new URL(BETA_VERSION_URL);
		} else {
			url = new URL(VERSION_URL);
		}
		return url;
	}

	@Override
	public void buildFromHtml(List<String> html) {
		if (html.size() > 0)
			version = html.remove(0);
		if (html.size() > 0) {
			StringBuilder sb = new StringBuilder();
			for (String s : html) {
				if (sb.length() > 0)
					sb.append("\n");
				sb.append(s);
			}
			news = sb.toString();
		}
	}

	public String getVersion() {
		return version;
	}

	public String getNews() {
		return news;
	}
}
